module.exports = function($scope, $state, $stateParams, $modalInstance,$resource,toaster){
    $scope.info = {
        'start_cardno' : '',
        'end_cardno' : '',
        'company_code' : '',
        'mobile' : '',
        'num' : ''
    };
    
    $scope.ok = function(){
        var reg = /^[\w]{12}$/;
        if(!$scope.info.start_cardno.match(reg)){
            alert('卡号必须为12位');
            return;
        } 
        if(!$scope.info.end_cardno.match(reg)){
            alert('卡号必须为12位');
            return;
        } 
        if ($scope.info.start_cardno > $scope.info.end_cardno){
            alert('结束卡号必须大于起始卡号')
            return;
        }
        $resource('/api/ac/mc/merchantOrderJuYouCardService/createFaKaForWXSale', {}, {}).save($scope.info, function (res) {
          if (res.errcode === 0) {
            toaster.success({ title: '', body: '添加成功' });
            $modalInstance.close();
          } else {
            toaster.error({ title: '', body: res.errmsg });
          }
        });
    }
    $scope.changes = function(){
        if ($scope.info.end_cardno != '' && $scope.info.start_cardno != '') {
            $scope.info.num = $scope.info.end_cardno - $scope.info.start_cardno + 1;
        }
    }
    $scope.change = function(){
        if ($scope.info.end_cardno != '' && $scope.info.start_cardno != '') {
            $scope.info.num = $scope.info.end_cardno - $scope.info.start_cardno + 1;
        }
    }

    $scope.cancel = function () {
      $modalInstance.dismiss('cancel');
    };
};